<?php

namespace common\models;

use Yii;

/**
 * This is the model class for table "mkt_source_member".
 *
 * @property string $id
 * @property string $user_id
 * @property string $area_id
 * @property string $member_count
 * @property string $member_quanlity
 * @property string $member_age_min
 * @property string $member_age_max
 */
class MktSourceMember extends \common\wosotech\base\ActiveRecord
{
    public $parent_area_id;
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'mkt_source_member';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['user_id', 'area_id', 'member_count', 'member_quanlity', 'member_age_min', 'member_age_max'], 'integer'],
            [['parent_area_id'],'safe']
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'user_id' => '用户编号',
            'area_id' => '会员区域',
            'member_count' => '会员数量',
            'member_quanlity' => '会员质量(年消费额)',
            'member_age_min' => '会员最小年龄',
            'member_age_max' => '会员最大年龄',
        ];
    }

    /**
     * @inheritdoc
     * @return MktSourceMemberQuery the active query used by this AR class.
     */
    public static function find()
    {
        return new MktSourceMemberQuery(get_called_class());
    }

    public function getUser()
    {
        return $this->hasOne(MktUser::className(), ['id' => 'user_id']);
    }

    public function getTheMember_count()
    {
        return \common\wosotech\Util::getShortInt($this->member_count);
    }

    public function getTheMember_quanlity()
    {
        return \common\wosotech\Util::getShortInt($this->member_quanlity);
    }

    public function getArea()
    {
        return $this->hasOne(MktArea::className(), ['id' => 'area_id']);
    }

    public function getIndustryPaths()
    {
        return empty($this->industry) ? '' : $this->industry->getPaths();
    }

    public function getAreaPaths()
    {
        return empty($this->area) ? '' : $this->area->getPaths();
    }

    public static function getMemberCountOption($key = null)
    {
        $arr = array(
            50 => '50',
            100 => '100',
            200 => '200',
            500 => '500',
        );
        return $key === null ? $arr : (isset($arr[$key]) ? $arr[$key] : '');
    }

    public static function getMemberQuanlityOption($key = null)
    {
        $arr = array(
            30000 => '3W',
            50000 => '5W',
            100000 => '10W',
            150000 => '15W',            
            200000 => '20W',
        );
        return $key === null ? $arr : (isset($arr[$key]) ? $arr[$key] : '');
    }

/*
0岁 	孕妈妈
0-3 	婴童
3-6 	幼儿
6-12 	小学生
12-15 	初中生


15-18 	高中生
18-24 	大学生
24-36 	职场新锐
36-48 	职场精英
48-60 	成功人士
*/
    public static function getMemberAgeMinOption($key = null)
    {
        $arr = array(
            18 => '18',
            25 => '25',
            30 => '30',
            40 => '40',
        );
        return $key === null ? $arr : (isset($arr[$key]) ? $arr[$key] : '');
    }

    public static function getMemberAgeMaxOption($key = null)
    {
        $arr = array(
            25 => '25',
            35 => '35',
            45 => '45',
            55 => '55',
        );
        return $key === null ? $arr : (isset($arr[$key]) ? $arr[$key] : '');
    }
    
}
